package com.sunkq.atomic;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.concurrent.atomic.AtomicReference;

@Getter@Setter
@AllArgsConstructor
@ToString
class User{
    private String name;
    private int age;
}



public class AtomicReferenceDemo {
    public static void main(String[] args) {
        AtomicReference<User>atomicReference = new AtomicReference<>();
        User z3 = new User("zhangsan",22);
        User l4 = new User("lisi",25);
        atomicReference.set(z3);
        System.out.println(atomicReference.compareAndSet(z3, l4)+"当前user为："+atomicReference.get().toString());
        System.out.println(atomicReference.compareAndSet(z3, l4)+"当前user为："+atomicReference.get().toString());

    }
}
